package it.intecs.pisa.smarcos.base;


public class Lists {

	BeepManager beepManager;
	
	int numOfElements;
	int position = -1;
	
	boolean beepFlagStart = false;
	boolean beepFlagEnd   = false;
	
	public Lists(int noe, BeepManager beepMngr){
		numOfElements = noe;
		beepManager = beepMngr;
	}


	public int Movement(String moveEvent){

		if (moveEvent.equals(GestureIntents.INTENT_GESTURE_SELECT)) {

			beepFlagStart = false;
			beepFlagEnd = false;
		} 
		else if (moveEvent.equals(GestureIntents.INTENT_GESTURE_RIGHT)){

			if ((position == numOfElements - 1)  && beepFlagStart == false){
				beepManager.playBeepSound();
				beepFlagEnd = true;
				return -1;
			}

			if ((beepFlagStart == false) || position == -1)
				position++;
			beepFlagStart = false;
		}
		else if(moveEvent.equals(GestureIntents.INTENT_GESTURE_LEFT)){

			if ((position == 0 || position == -1) && beepFlagEnd == false){
				beepManager.playBeepSound();
				beepFlagStart = true;
				return -1;
			}

			if (beepFlagEnd == false)
				position--;
			else beepFlagEnd = false;	
		}
		
		return position;
	} 
}
